package com.skycong.viewpage;

import android.app.Activity;
import android.graphics.Color;
import android.support.v4.view.PagerTabStrip;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends Activity {
   private ViewPager viewPager;
   private PagerTabStrip tab;
   private List<View> viewList;
   private List<String> titleList;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        viewList = new ArrayList<View>();
        titleList = new ArrayList<String>();
        //将Layout布局转换成View对象
        View view1 = View.inflate(this, R.layout.view1, null);
        View view2 = View.inflate(this, R.layout.view2, null);
        View view3 = View.inflate(this, R.layout.view3, null);
        View view4 = View.inflate(this, R.layout.view4, null);
        //将View放在数据源中,通过View对象作为listView数据源
        viewList.add(view1);
        viewList.add(view2);
        viewList.add(view3);
        viewList.add(view4);
        titleList.add("第一页面");
        titleList.add("第二页面");
        titleList.add("第三页面");
        titleList.add("第四页面");

        //实例化viewPager
        viewPager = (ViewPager) findViewById(R.id.viewpage);
        tab = (PagerTabStrip) findViewById(R.id.viewtab);
        ViewPageAdapter viewPageAdapter = new ViewPageAdapter(viewList,titleList);
        viewPager.setAdapter(viewPageAdapter);

        //为PagerTabStrip设置一些属性
          tab.setBackgroundColor(Color.GREEN);//设置背景颜色
          tab.setTextColor(Color.RED);//设置文字颜色
          tab.setDrawFullUnderline(false);//去掉下化线



    }
}
